﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class MasterPage : System.Web.UI.MasterPage
{
    DatabaseDataContext db = new DatabaseDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] != null)
        {

        }
    }
    protected void bnt_dangnhap_Click(object sender, EventArgs e)
    {
        

    }

    public void setlogin()
    {
        if (Page.IsValid)
        {
            string username = txt_username.Text;
            string password = txt_password.Text;
            string key = System.Configuration.ConfigurationManager.AppSettings["KeySecurity"].ToString();

            var user = (from c in db.Tb_Users
                            select new { c }).SingleOrDefault();

            if (user.c.Email == username && user.c.MatKhau == algorithmPassword.Encode(password, key))
            {
                Session["User"] = user.c.Email;
                Response.Redirect("Default.aspx");
            }
        }
    }
}
